package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        
        //获取今天时间
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周的第一天
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月的第一天
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //获取今天新增会员人数
        Long todayNewMember = memberDao.todayNewMember(today);
        //获取总会员数
        Long totalMember = memberDao.totalMember();
        //获取本周新增会员人数
        Long thisWeekNewMember = memberDao.getAfterDayByDate(thisWeekMonday);
        //获取本月新增会员人数
        Long thisMonthNewMember = memberDao.getAfterDayByDate(firstDay4ThisMonth);

        //获取今日预约数
        Long todayOrderNumber = orderDao.todayOrderNumber(today);
        //获取今日到诊数
        Long todayVisitsNumber = orderDao.todayVisitsNumber(today);
        //获取本周预约数
        Long thisWeekOrderNumber = orderDao.getOrderNumberByAfterDay(thisWeekMonday);
        //获取本周到诊数
        Long thisWeekVisitsNumber = orderDao.getVisitNumberByAfterDay(thisWeekMonday);
        //获取本月预约数
        Long thisMonthOrderNumber = orderDao.getOrderNumberByAfterDay(firstDay4ThisMonth);
        //获取本月到诊数
        Long thisMonthVisitsNumber = orderDao.getVisitNumberByAfterDay(firstDay4ThisMonth);

        //获取热门套餐数
        List<Map<String,Object>> hotSetmeal = orderDao.getHostSetmeal();

        Map<String,Object> map = new HashMap<>();
        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);

        return map;
    }
}
